﻿using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Graphics;

namespace Ultima.Xna.Graphics.UI.Gumps
{
    public class GumpImage : GumpEntry
    {
        private Texture2D _texture;
        private int _hue;
        private int _gumpId;
        private bool _dirty;

        public int Hue
        {
            get { return _hue; }
            set
            {
                _hue = value;
                _dirty = true;
            }
        }

        public int GumpId
        {
            get { return _gumpId; }
            set
            {
                _gumpId = value;
                _dirty = true;
            }
        }

        public Texture2D Texture
        {
            get { return _texture; }
            set 
            {
                _texture = value; 
            }
        }

        public GumpImage(Game game)
            : base(game)
        {
            Focusable = false;
        }

        public override void Initialize()
        {
            base.Initialize();

            _dirty = false;
            _texture = Data.Gumps.CreateTexture(Game.GraphicsDevice, _gumpId);
            Size = new Vector2(_texture.Width, _texture.Height);
        }

        public override void Draw(GameTime gameTime)
        {
            if (_dirty)
            {
                _dirty = false;
                _texture = Data.Gumps.CreateTexture(Game.GraphicsDevice, _gumpId);
                Size = new Vector2(_texture.Width, _texture.Height);
            }

            Manager.Renderer.Render(this);

            base.Draw(gameTime);
        }
    }
}
